<template>
  <div class="screenType">
    <div class="mask"></div>
    <div class="screenTypeContent">
      <div class="screenTypeTop">
        <p>筛选款号</p>
        <i class="el-icon-close" @click="close"></i>
      </div>
      <div style="padding:0 20px;">
        <div class="screenTypeBtn">
          <span>编号条件</span>
          <el-input v-model="input" style="width: 160px;margin: 0 10px;height:30px" @keyup.enter.native="search"></el-input>
          <el-button @click="search" icon="el-icon-search" type="primary">查询</el-button>
          <el-button @click="save" icon="el-icon-document-checked">保存</el-button>
          <el-button @click="dele" icon="el-icon-delete">删除</el-button>
          <el-button @click="empty" icon="el-icon-delete">清空</el-button>
        </div>
        <div style="display:flex">
          <div class="box1">
            <span>筛选条件</span>
            <el-select v-model="value" 
              style="width: 200px;margin-left:10px;"
              @change="quarterRange">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <el-table
              style="margin-top:15px"
              height="450"
              :header-cell-style="{padding:0,height:'40px',background:'#f4f4f4'}"
              :cell-style="{padding:0,height:'36px'}"
              :data="tableData"
              @selection-change="quarterSelectionChange">
              <el-table-column
                type="selection"
                width="50">
              </el-table-column>
              <el-table-column
                prop="name"
                label="季度">
              </el-table-column>
            </el-table>
          </div>
          <div class="box2">
            <el-table
              height="495"
              :header-cell-style="{padding:0,height:'40px',background:'#f4f4f4'}"
              :cell-style="{padding:0,height:'36px'}"
              :data="tableData2"
              @selection-change="styleSelectionChange">
              <el-table-column
                type="selection"
                width="50">
              </el-table-column>
              <el-table-column
                prop="styleNumber"
                label="款号"
                width="180">
              </el-table-column>
              <el-table-column
                prop="commodityName"
                label="品名名称">
              </el-table-column>
              <el-table-column
                prop="quarter"
                label="季度"
                width="80">
              </el-table-column>
            </el-table>
          </div>
          <div class="box3">
            <el-table
              height="495"
              :header-cell-style="{padding:0,height:'40px',background:'#f4f4f4'}"
              :cell-style="{padding:0,height:'36px'}"
              highlight-current-row
              :data="tableData3"
              @row-click="rowClick">
              <el-table-column
                prop="quarter"
                label="季度"
                width="80">
              </el-table-column>
              <el-table-column
                prop="styleNumber"
                label="款号"
                width="180">
              </el-table-column>
              <el-table-column
                prop="operator"
                label="操作员">
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import{ getQuarter, getNumber, getQnumber } from '../../../../network/quarter'

export default {
  data(){
    return {
      input: '',
      value: '全部',
      options: [
        {label:'全部',value:'全部'},
        {label:'春夏',value:'春夏'},
        {label:'秋冬',value:'秋冬'}
      ],

      deleStyle: '',

      selectStyle: [],
      selectQuarter: [],

      tableData: [],
      quarterList: [],
      tableData2: [],
      tableData3: [],

      quarterMap: {}
    }
  },
  watch: {
    input(a,b){
      this.input = a.toUpperCase().trim()
    }
  },
  methods: {
    close(){
      this.$emit('closeScreenType')
    },
    search(){
      this.deleStyle = ''
      if (this.input) {
        getNumber([this.input]).then(res => {
          this.tableData2 = res.data.data || []
          this.tableData2.forEach(e => {
            e.quarter = this.quarterMap[e.quarter]
          })
        })
      } else {
        let list = []
        this.selectQuarter.forEach(e => {
          list.push(e.id)
        })
        getQnumber(list).then(res => {
          this.tableData2 = res.data.data || []
          this.tableData2.forEach(e => {
            e.quarter = this.quarterMap[e.quarter]
          })
        })
      }
    },
    save(){
      this.deleStyle = ''
      this.tableData3 = this.selectStyle
      this.$emit('changeConditions', this.tableData3)
    },
    dele(){
      if (this.deleStyle == '') {
        this.$alert('请先选择一条数据再进行删除操作', '', {
          confirmButtonText: '确定'
        })
      }

      for (let i = 0, len = this.tableData3.length; i < len; i++) {
        const e = this.tableData3[i]
        if (this.deleStyle == e.styleNumber) {
          this.tableData3.splice(i,1)
          this.$emit('changeConditions', this.tableData3)
          return
        }
      }
    },
    empty(){
      this.tableData3 = []
      this.$emit('changeConditions', this.tableData3)
    },
    quarterRange(e){
      // console.log(e)
      if (e == '全部') {
        this.tableData = this.quarterList
      } else if (e == '春夏') {
        this.tableData = []
        this.quarterList.forEach(f => {
          if (f.name.indexOf('春') != -1 || f.name.indexOf('夏') != -1) {
            this.tableData.push(f)
          }
        })
      } else if (e == '秋冬') {
        this.tableData = []
        this.quarterList.forEach(f => {
          if (f.name.indexOf('秋') != -1 || f.name.indexOf('冬') != -1) {
            this.tableData.push(f)
          }
        })
      }
    },
    quarterSelectionChange(e){
      this.selectQuarter = e
    },
    styleSelectionChange(e){
      this.selectStyle = e
    },
    rowClick(e){
      // console.log(e)
      this.deleStyle = e.styleNumber
    }
  },
  created(){
    getQuarter().then(res => {
      if (res.data.code == 200) {
        this.quarterList = res.data.data || []
        this.tableData = this.quarterList
        this.quarterMap = {}
        this.quarterList.forEach(e => {
          this.quarterMap[e.id] = e.name
        })
      }
    })
  }
}
</script>

<style scoped>
  .screenType .mask{
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    opacity: 0.3;
    z-index: 9;
  }
  .screenType .screenTypeContent{
    position: fixed;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    width: 1200px;
    height: 650px;
    z-index: 99;
    background-color: white;
  }
  .screenType .screenTypeContent .screenTypeTop{
    height: 40px;
    background-color: #f8f8f8;
  }
  .screenType .screenTypeContent .screenTypeTop p{
    float: left;
    line-height: 40px;
    padding-left: 20px;
    font-weight: bold;
  }
  .screenType .screenTypeContent .screenTypeTop i{
    float: right;
    line-height: 40px;
    padding: 0 16px;
  }
  .screenType .screenTypeBtn{
    background-color: #f8f8f8;
    margin: 20px 0;
    padding: 15px 20px;
    height: 60px;
  }

  .screenType .box1{
    width: 300px;
    border-right: 2px #f8f8f8 solid;
    padding-right: 15px;
  }
  .screenType .box2{
    width: 500px;
    border-right: 2px #f8f8f8 solid;
    padding: 0 15px;
  }
  .screenType .box3{
    width: 360px;
    padding-left: 15px;
  }
</style>

<style>
  .screenType .el-input__inner{
    height: 30px;
  }
</style>